'use strict';
module.exports = () => async (ctx, next) => {
  const { request, response } = ctx;
  const queryString = ctx.request.querystring
    ? 'Query: ' + ctx.request.querystring
    : '';
  const body = request.rawBody ? 'Body: ' + request.rawBody : '';
  if (ctx.method !== 'HEAD') {
    ctx.logger.info(`---> Init Request ${queryString} ${body}`);
  }
  await next();
  if (ctx.method !== 'HEAD') {
    if (response.status === 200) {
      ctx.logger.info(
        `<--- HTTP Code: ${response.status} Code: ${
          response.body.code
        } Message: ${response.body.message}`
      );
    }
  }
};
